<template>
  <app-page card full>
    <app-page-main>
      <template #header>
        <div class="app-query"></div>
        <div class="app-action">
          <el-button type="primary" plain icon="plus" @click="pageActions.handleAdd()">添加</el-button>
        </div>
      </template>

      <el-table v-loading="pageData.loading" :data="pageData.data" stripe style="width: 100%">
        <el-table-column prop="configName" label="配置名称" show-overflow-tooltip></el-table-column>
        <el-table-column prop="configType" label="配置标识" show-overflow-tooltip></el-table-column>
        <el-table-column label="公开">
          <template #default="{ row }">
            <el-switch
              :before-change="
                () =>
                  pageActions.handleUpdate(
                    row,
                    { isPublic: !row.isPublic },
                    !row.isPublic ? '确认上线？' : '确认下线？',
                    '已修改'
                  )
              "
              v-model="row.isPublic"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template #default="{ row }">
            <el-button
              link
              type="primary"
              icon="edit"
              @click="pageActions.handleEdit(row)"
              :disabled="row.isSystem"
              >编辑
            </el-button>
            <el-button
              link
              type="primary"
              icon="delete"
              @click="pageActions.handleDelete(row)"
              :disabled="row.isSystem"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </app-page-main>

    <!-- 新增/编辑 -->
    <jax-dialog-edit
      v-model="pageData.detail"
      v-model:show="pageData.shwoEdit"
      :json="formJson"
      @submit="pageActions.handleSubmit()"
      :formProps="{ labelWidth: '90px' }"
    />
  </app-page>
</template>

<script setup>
import { usePageList } from 'jax-node'

const { pageData, pageActions } = usePageList()

const formJson = computed(() => {
  return [
    { name: 'configName', label: '配置名称', required: true },
    { name: 'configType', label: '配置标识', required: true },
  ]
})
</script>

<style lang="scss" scoped></style>
